home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / gfx / show / swfplayersrc.lha / Player / screen.c < prev    next >
C/C++ Source or Header  |  2002-11-05  |  8KB  |  256 lines

  1. /*
  2. **
  3. ** $VER: screen.c 0.5 (05.11.02)
  4. ** Description
  5. **
  6. ** (C) Copyright 1999 Paul Hill
  7. ** (C) Copyright 2002 Alexandre Balaban
  8. **
  9. ** $HISTORY :
  10. **        - 0.5, 05.11.02 : o Added TRACE debug informations
  11. **                          o Added pack pragma directives for PPC compilation
  12. **        - 0.4, 04.11.02 : Improved PPC includes
  13. **        - 0.3, 03.10.02 : Add loop setting menu
  14. **        - 0.2, 27.07.02 : Clean-up
  15. **        - 0.1, 27.02.99 : Original version by Paul Hill
  16. **
  17. */
  18.  
  19. #pragma pack(2)
  20.  
  21. #ifndef __PPC__
  22. #include <proto/intuition.h>
  23. #include <proto/graphics.h>
  24. #include <proto/asl.h>
  25. #include <proto/gadtools.h>
  26. #else
  27. #include </ADE/os-includeppc/proto/intuition.h>
  28. #include </ADE/os-includeppc/proto/graphics.h>
  29. #include </ADE/os-includeppc/proto/asl.h>
  30. #include </ADE/os-includeppc/proto/gadtools.h>
  31. #endif
  32.  
  33. #pragma pack()
  34.  
  35. #include <stdio.h>
  36. #include "swfplayer.h"
  37.  
  38. static APTR VisualInfo = NULL;
  39. static struct RastPort video_temprp;
  40. static struct BitMap video_tmp_bm = { 0, 0, 0, 0, 0, {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL} };
  41.  
  42. //static void swf_about(struct MenuItem *menuitem);
  43. //static void swf_seperatescreen(struct MenuItem *menuitem);
  44. void swf_quit(struct MenuItem *menuitem);
  45.  
  46. static struct NewMenu SWFPlayerNewMenu[] =
  47. {
  48.     {NM_TITLE,    (STRPTR)"Project",                NULL,    0,            NULL,    NULL},
  49. //    {NM_ITEM,    (STRPTR)"Open",                 "O",    0,            0L,        (APTR) MENU_OPEN},
  50. //    {NM_ITEM,    (STRPTR)NM_BARLABEL,            NULL,    0,            0L,        NULL},
  51.     {NM_ITEM,    (STRPTR)"Properties",            "I",    0,            0L,        (APTR) MENU_INFO},
  52.     {NM_ITEM,    (STRPTR)"About",                "?",    0,            0L,        (APTR) MENU_ABOUT},
  53.     {NM_ITEM,    (STRPTR)NM_BARLABEL,            NULL,    0,            0L,        NULL},
  54.     {NM_ITEM,    (STRPTR)"Quit",                    "Q",    0,            0L,        (APTR) MENU_QUIT},
  55.  
  56.     {NM_TITLE,    (STRPTR)"Control",                NULL,    0,            NULL,    NULL},
  57.     {NM_ITEM,    (STRPTR)"Pause",                "P",    0,            0L,        (APTR) MENU_PAUSE},
  58.     {NM_ITEM,    (STRPTR)"Continue",                "C",    0,            0L,        (APTR) MENU_CONTINUE},
  59.     {NM_ITEM,    (STRPTR)"Rewind",                "R",    0,            0L,        (APTR) MENU_REWIND},
  60.     {NM_ITEM,    (STRPTR)"Zoom In",                "+",    0,            0L,        (APTR) MENU_ZOOMIN},
  61.     {NM_ITEM,    (STRPTR)"Zoom Out",                "-",    0,            0L,        (APTR) MENU_ZOOMOUT},
  62. //    {NM_ITEM,    (STRPTR)"Step",                    NULL,    0,            0L,        (APTR) MENU_STEP},
  63.  
  64.       {NM_TITLE,    (STRPTR)"Settings",                NULL,    0,            NULL,    NULL},
  65. //    {NM_ITEM,    (STRPTR)"Use Seperate Screen",    NULL,    CHECKIT,    0L,        MENU_SEPERATE},
  66. //    {NM_ITEM,    (STRPTR)NM_BARLABEL,            NULL,    0,            0L,        NULL},
  67. //    {NM_ITEM,    (STRPTR)"Volume",                NULL,    0,            NULL,    NULL},
  68. //    {NM_SUB,    (STRPTR)"Off",                    NULL,    0,            0L,        NULL},
  69. //    {NM_SUB,    (STRPTR)"Quiet",                NULL,    0,            0L,        NULL},
  70. //    {NM_SUB,    (STRPTR)"Normal",                NULL,    0,            0L,        NULL},
  71. //    {NM_SUB,    (STRPTR)"Loud",                    NULL,    0,            0L,        NULL,        //(APTR)Project0Item15},
  72.     {NM_ITEM,    (STRPTR)"Loop play",            "L",    CHECKIT|CHECKED,    0L,        (APTR) MENU_LOOPPLAY},
  73. //    {NM_ITEM,    (STRPTR)NM_BARLABEL,            NULL,    0,            0L,        NULL},
  74. //    {NM_ITEM,    (STRPTR)"Save As Defaults",        "D",    0,            0L,        NULL},
  75.     {NM_END,    NULL,                            NULL,    0,            0L,        NULL}
  76. };
  77.  
  78.  
  79. int open_swf_window()
  80. {
  81.     /* Adjust the width & height if MAXWIDTH or MAXHEIGHT were specified on the command line */
  82.     if (args[OPT_MAXWIDTH])
  83.         if (swfinfo.width > (* (ULONG *) args[OPT_MAXWIDTH])) swfinfo.width = * (ULONG*) args[OPT_MAXWIDTH];
  84.  
  85.     if (args[OPT_MAXHEIGHT])
  86.         if (swfinfo.height > (* (ULONG *) args[OPT_MAXHEIGHT])) swfinfo.height = * (ULONG*) args[OPT_MAXHEIGHT];
  87.  
  88.  
  89.  
  90. #ifdef FULLSCREEN_CODE
  91.     if (swfinfo.fullscreen)
  92.     {
  93.         /* We're running fullscreen, not in a window */
  94.  
  95.         if ((swfinfo.screen = OpenScreenTags(NULL,
  96.                     SA_Left,            0,
  97.                     SA_Top,            0,
  98.                     SA_Width,        swfinfo.width,
  99.                     SA_Height,        swfinfo.height,
  100.                     SA_DisplayID,    swfinfo.modeid,
  101.                     SA_Depth,        swfinfo.depth,
  102.                     SA_Title,        (ULONG) "SWFPlayer",
  103.                     TAG_DONE)))
  104.         {
  105.             swfinfo.window = OpenWindowTags(NULL,
  106.                                         WA_InnerWidth,                (ULONG) swfinfo.width,
  107.                                         WA_InnerHeight,            (ULONG) swfinfo.height,
  108.                                         WA_CloseGadget,    FALSE,
  109.                                         WA_DepthGadget,    FALSE,
  110.                                         WA_DragBar,            FALSE,
  111.                                         WA_SizeGadget,        FALSE,
  112.                                         WA_RMBTrap,            FALSE,
  113.                                         WA_Activate,        TRUE,
  114.                                         WA_Borderless,        TRUE,
  115.                                         WA_IDCMP,            IDCMP_MENUVERIFY | IDCMP_MENUPICK | IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW | IDCMP_VANILLAKEY | IDCMP_RAWKEY | IDCMP_INTUITICKS | IDCMP_MOUSEBUTTONS,
  116.                                         WA_Activate,        TRUE,
  117.                                         WA_CustomScreen,    (ULONG) swfinfo.screen,
  118.                                         TAG_END);
  119.         }
  120.     }
  121.     else
  122. #endif
  123.     {
  124.         /* We're running in a window on a pubscreen */
  125.         swfinfo.screen = LockPubScreen((char *) swfinfo.pubscreenname);
  126.         if (!swfinfo.screen)
  127.         {
  128.             fprintf(stderr,"Can't lock pubscreen\n");
  129.             return 0;
  130.         }
  131.  
  132.         swfinfo.window = OpenWindowTags(NULL,
  133.                                     WA_InnerWidth,                (ULONG) swfinfo.width,
  134.                                     WA_InnerHeight,            (ULONG) swfinfo.height,
  135.                                     WA_CloseGadget,            TRUE,
  136.                                     WA_DepthGadget,            TRUE,
  137.                                     WA_DragBar,                    TRUE,
  138.                                     WA_Title,                    (ULONG) "swfplayer",
  139.                                     WA_SizeGadget,                FALSE,
  140.                                     WA_IDCMP,                    IDCMP_MENUPICK |
  141.                                                                     IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW |
  142.                                                                     IDCMP_VANILLAKEY | IDCMP_RAWKEY |
  143.                                                                     IDCMP_INTUITICKS | IDCMP_MOUSEBUTTONS |
  144.                                                                     IDCMP_ACTIVEWINDOW | IDCMP_INACTIVEWINDOW,
  145.                                     WA_Activate,                TRUE,
  146.                                     WA_PubScreen,                (ULONG) swfinfo.screen,
  147.                                     WA_PubScreenFallBack,    TRUE,
  148.                                     TAG_END);
  149.     }
  150.  
  151.     if (!swfinfo.window)
  152.     {
  153.         fprintf(stderr,"no window\n");
  154.         return 0;
  155.     }
  156.  
  157.     swfinfo.depth = GetBitMapAttr(swfinfo.screen->RastPort.BitMap,BMA_DEPTH);
  158.     TRACE( "*** GetBitMapAttr passed !\n" );
  159.  
  160.     /* Cache some variables for later */
  161.     swfinfo.winbordertop  = swfinfo.window->BorderTop;
  162.     swfinfo.winborderleft = swfinfo.window->BorderLeft;
  163.     swfinfo.rport         = swfinfo.window->RPort;
  164.  
  165.     /* There's a chance that the desired window width & height couldn't be
  166.         met, so update the width & height variables with the real width &
  167.         height */
  168.     swfinfo.width  = swfinfo.window->Width  - swfinfo.window->BorderLeft - swfinfo.window->BorderRight;
  169.     swfinfo.height = swfinfo.window->Height - swfinfo.window->BorderTop  - swfinfo.window->BorderBottom;
  170.  
  171.     /* Layout the gadtools menus */
  172.     if ((VisualInfo = GetVisualInfo(swfinfo.screen, TAG_DONE )))
  173.     {
  174.         if ((swfinfo.SWFPlayerMenus = CreateMenus(SWFPlayerNewMenu, GTMN_FrontPen, 0L, TAG_DONE)))
  175.         {
  176.             LayoutMenus(swfinfo.SWFPlayerMenus, VisualInfo, TAG_DONE);
  177.  
  178.             SetMenuStrip(swfinfo.window, swfinfo.SWFPlayerMenus);
  179.             GT_RefreshWindow(swfinfo.window, NULL);
  180.         }
  181.     }
  182.  
  183.     /* Setup the temporary rastport required for kickstart 3.0 */
  184.     if (!swfinfo.kick31)
  185.     {
  186.         int depth;
  187.         TRACE( "*** kickstart 3.0 or earlier detected, setting up temporary rastport...\n" );
  188.         InitBitMap (&video_tmp_bm, swfinfo.depth, swfinfo.width, 1);
  189.  
  190.         for (depth = 0; depth < swfinfo.depth; depth++)
  191.         {
  192.             if ((video_tmp_bm.Planes[depth] = (PLANEPTR)AllocRaster (swfinfo.width, 1)) == NULL)
  193.             {
  194.                 fprintf(stderr,"AllocRaster() failed");
  195.                 return 0;
  196.             }
  197.         }
  198.  
  199.         video_temprp = *swfinfo.rport;
  200.         video_temprp.Layer = NULL;
  201.         video_temprp.BitMap = &video_tmp_bm;
  202.  
  203.         swfinfo.tmprport = &video_temprp;
  204.     }
  205.  
  206.     TRACE( "*** open_swf_window() exit normally !\n" );
  207.     return 1;
  208. }
  209.  
  210.  
  211. void close_swf_window()
  212. {
  213.     if (swfinfo.window)
  214.     {
  215.         if (!swfinfo.kick31)
  216.         {
  217.             int depth;
  218.             for (depth = 0; depth < swfinfo.depth; depth++)
  219.             {
  220.                 if (video_tmp_bm.Planes[depth] != NULL)
  221.                 {
  222.                     FreeRaster (video_tmp_bm.Planes[depth], swfinfo.width, 1);
  223.                     video_tmp_bm.Planes[depth] = NULL;
  224.                 }
  225.             }
  226.             swfinfo.tmprport = NULL;
  227.         }
  228.  
  229.         if (VisualInfo)
  230.         {
  231.             if (swfinfo.SWFPlayerMenus)
  232.             {
  233.                 ClearMenuStrip(swfinfo.window);
  234.                 FreeMenus(swfinfo.SWFPlayerMenus);
  235.                 swfinfo.SWFPlayerMenus = NULL;
  236.             }
  237.             FreeVisualInfo(VisualInfo);
  238.         }
  239.  
  240.         CloseWindow(swfinfo.window);
  241.         swfinfo.window = NULL;
  242.     }
  243.     if (swfinfo.screen)
  244.     {
  245. #ifdef FULLSCREEN_CODE
  246.         if (swfinfo.fullscreen)
  247.             CloseScreen(swfinfo.screen);
  248.         else
  249. #endif
  250.             UnlockPubScreen(NULL,swfinfo.screen);
  251.  
  252.         swfinfo.screen = NULL;
  253.     }
  254. }
  255.  
  256.